package com.shiroha.video.config;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FeignRequestInterceptor implements RequestInterceptor {

    private final String apiKey;

    private static final Logger logger = LoggerFactory.getLogger(FeignRequestInterceptor.class);

    public FeignRequestInterceptor(String apiKey) {
        this.apiKey = apiKey;
    }

    @Override
    public void apply(RequestTemplate template) {
        template.header("X-Emby-Token", apiKey);
        template.header("Content-Type", "application/json");
        logger.info("Feign Request: {}", template.url());
        logger.info("Feign Headers: {}", template.headers());
        logger.info("Feign Body: {}", template.body() != null ? new String(template.body()) : "Empty Body");
    }
}
